package com.dongao.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.dongao.model.Course;

public class OfflineSubjectActivity extends ListActivity {
	
	private List<Course> courses;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_subject);
		
		Intent intent = getIntent();
		courses = (List<Course>)intent.getSerializableExtra("courses");
		
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		
		for (Course course : courses) {
			Map<String,String> map = new HashMap<String, String>();
			map.put("courseName", course.getClassName());
			map.put("progress", course.getCwProgress());
			
			list.add(map);
		}
		
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				R.layout.course_item, new String[] { "courseName", "progress" },
				new int[] { R.id.course_name, R.id.course_progress });
		
		setListAdapter(simpleAdapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Course course = courses.get(position);
		System.out.println("course:"+course);
		System.out.println("course-cws:"+course.getCws());
		Intent intent = new Intent();
		intent.putExtra("course", course);
		intent.setClass(this, CourseDetailActivity.class);
		startActivity(intent);
		super.onListItemClick(l, v, position, id);
	}
	
	
}
